package cloud.shyidong.admin.auth.configurer;

import cloud.shyidong.admin.auth.interceptor.AuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * @Description TODO
 * @Author syd
 * @Date 2023/4/17
 */
@Configuration
@RefreshScope
public class AuthWebMvcConfigurer implements WebMvcConfigurer {
    
    private List<String> authInterceptorPath;
    
    private AuthInterceptor authInterceptor;
    
    @Value("#{'${auth.interceptor.path}'.split(',')}")
    public void setAuthInterceptorPath(List<String> authInterceptorPath) {
        this.authInterceptorPath = authInterceptorPath;
    }
    
    @Autowired
    public void setAuthInterceptor(AuthInterceptor authInterceptor) {
        this.authInterceptor = authInterceptor;
    }
    
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authInterceptor).addPathPatterns(authInterceptorPath);
    }
    
    
}
